<template>
  <div class="side">
    <div class="regiser">
      <el-row>
        <el-button type="primary" @click="createData" class="dakai">提交</el-button>
      </el-row>
    </div>
    <div style="width:100%;">
      <el-form ref="dataForm" :model="InvitationRegisterSet" label-position="right" label-width="180px">
        <el-form-item label="邀请码设置">
          <el-radio-group v-model="InvitationRegisterSet.invitationCode">
            <el-radio label="1">开启</el-radio>
            <el-radio label="0">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="被邀请人注册奖励">
          <el-input v-model="InvitationRegisterSet.registerReward"/>
          元面值抵价优惠券 （可用于全站消费）
        </el-form-item>
        <el-form-item label="邀请人邀请奖励">
          <el-input v-model="InvitationRegisterSet.invitationReward"/>
          元面值抵价优惠券 （可用于全站消费）<br>
          <el-checkbox v-model="InvitationRegisterSet.hasConsume">被邀请人有消费行为后才能获得优惠券</el-checkbox>
        </el-form-item>
        <el-form-item label="优惠券有效时间">
          <el-input v-model="InvitationRegisterSet.validTime"/>
          天
        </el-form-item>
        <el-form-item label="邀请信息模板">
          <el-input :rows="6" v-model="InvitationRegisterSet.messageMasterplate" type="textarea" style="width:310px;"/>
        </el-form-item>
      </el-form>
    </div>
    <div class="foot">
      <div class="bianliang">通知变量说明：{{ siteName }}:网校名称 {{ registerUrl }}:注册链接的地址</div>
    </div>
  </div>
</template>

<script>
  import {addInvitationRegisterSetData, getInvitationRegisterSetData} from "@/api/system/invitation_register_set"
  import {getTenantId} from '@/utils/auth';

  export default {
    data() {
      return {
        siteName: '{{siteName}}',
        registerUrl: '{{registerUrl}}',
        InvitationRegisterSet: {
          invitationCode: '',
          registerReward: '',
          invitationReward: '',
          validTime: '',
          messageMasterplate: '',
          hasConsume: true
        }
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      fetchData() {
        getInvitationRegisterSetData(getTenantId()).then(response => {
          this.InvitationRegisterSet = response.data
        }).catch(err => {
          console.log(err)
        })
      },
      createData() {
        this.$refs["dataForm"].validate(valid => {
          if (valid) {
            this.InvitationRegisterSet.tenantId = getTenantId();
            addInvitationRegisterSetData(this.InvitationRegisterSet).then(() => {
              this.$notify({
                title: "成功",
                message: "创建成功",
                type: "success",
                duration: 2000
              });
              this.fetchData();
            })
          }
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .side {
    .el-input {
      width: 60px;
    }

    .foot {
      margin-top: 20px;
      padding: 15px 15px;
      border-radius: 5px;
      background-color: #d9edf7;
      color: #326f8f;
      border-left: 5px solid #50bfff;
    }
  }

  .regiser {
    width: 100%;
    height: 44px;
    line-height: 44px;
    padding-left: 10px;
    background-color: #e7e9ed;
    padding-top: 15px;
    padding-right: 34px;
  }

  .dakai {
    float: right;
    position: absolute;
    right: 10px;
    bottom: -25px;
  }
</style>
